/**
 * The problem is to write a method that checks whether two strings are Anagrams.
 * Two words are anagrams if they contain the same letters in any order. For example, "silent" and "listen" are anagrams.
 * @author Jhonny
 *
 */

import java.util.Scanner;

public class Anagrams {

	public static void main (String ARGC[])
	{

		Scanner scan = new Scanner(System.in);
		
		
		System.out.println("Enter the first string: ");
		char[] firstArr = scan.next().toCharArray();

		
		System.out.println("Enter the second string: ");
		char[] secondArr = scan.next().toCharArray();
		
		
		boolean same=true;
		
		if (firstArr.length==secondArr.length)
		{
			for (int i=0;i<firstArr.length; i++)
			{
				
				//look for this char in the second string
				char c = firstArr[i];
				boolean charsame = false;
				
				for (int x=0;x<secondArr.length;x++)
				{
					
					if( c == secondArr[x] )
					{
						charsame = true;
						secondArr[x]='0';
						break;
					}
				}
				
				if(!charsame)
				{
					same=false;
					break;
				}
			}
		}
		else
		{
			same = false;
			
		}
		
		System.out.println("These Two strings are " +  ( same ? "Anagrams":"Not Anagrams" ) );
		
		
		
		
		
		//System.out.println(firstString);
		//System.out.println(secondString);
		
		
		
	}
}
